﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuTouTiaoAssist.Util
{
    /// <summary>
    /// UI相关工具
    /// </summary>
    class UiUtil
    {
        /// <summary>
        /// 启用TextBox的Ctrl+A全选功能
        /// </summary>
        /// <param name="textBox"></param>
        public static void EnableTextBoxSelectAll(System.Windows.Forms.TextBox textBox)
        {
            textBox.KeyDown += (sender, args) =>
            {
                if (args.Control && args.KeyCode == Keys.A)
                    textBox.SelectAll();
            };
        }

        /// <summary>
        /// 清空PictureBox内容
        /// </summary>
        /// <param name="pb"></param>
        public static void ClearPictureBox(PictureBox pb)
        {
            var g = pb.CreateGraphics();
            g.Clear(pb.BackColor);
            g.Dispose();
        }

        /// <summary>
        /// 设置Esc退出窗体功能
        /// </summary>
        public static void SetCancelButton(Form frm)
        {
            Button btn = new Button();
            btn.Click += (sender, args) =>
            {
                if (frm.Modal)
                {
                    frm.DialogResult = DialogResult.Cancel;
                }
                else
                {
                    frm.Close();
                }
            };
            frm.CancelButton = btn;
        }
    }
}
